/**
 * 
 */
package uk.ac.ebi.curtain.utils.file.impl;

import java.util.ArrayList;
import java.util.List;

import uk.ac.ebi.curtain.utils.file.WriteUtil;

/**
 * @author mhaimel
 *
 */
public abstract class AbstractWriter implements WriteUtil {
	
	private static final int DEFAULT_SEQ_LINE_LEN = 60;
	private int sequLineLimit;
	
	public AbstractWriter(int sequLineLimit) {
		this.sequLineLimit = sequLineLimit;
	}
	
	public AbstractWriter() {
		this(DEFAULT_SEQ_LINE_LEN);
	}

	protected List<String> splitSequence(String sequence) {
		return splitSequence(sequence,getSequLineLimit());
	}
	
	protected List<String> splitSequence(String sequence, int lineLimit) {
		List<String> seqList = new ArrayList<String>();
		int iPos = 0;
		int iNext = 0;
		do {
			iNext = Math.min(sequence.length(), (iPos+lineLimit));
			seqList.add(sequence.substring(iPos,iNext));			
			iPos = iNext;
		} while (iPos < sequence.length());
		
		return seqList;
	}
	
	protected int getSequLineLimit() {
		return sequLineLimit;
	}
}
